package com.lzh.template.controller;


import com.lzh.template.common.BaseResponse;
import com.lzh.template.common.ResultUtil;
import com.lzh.template.model.dto.chart.AddChartDto;
import com.lzh.template.model.dto.chart.EditChartDto;
import com.lzh.template.model.dto.chart.GenChartByAIDto;
import com.lzh.template.model.dto.chart.QueryChartDto;
import com.lzh.template.model.vo.PageVo;
import com.lzh.template.model.vo.chart.GenChartVo;
import com.lzh.template.service.ChartService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (ChartEntity)表控制层
 *
 * @author luzhiheng
 * @since 2023-12-29 10:47:16
 */
@RestController
@RequestMapping("/chart")
public class ChartController {

    @Resource
    private ChartService chartService;

    /**
     * 分页条件查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/queryChartPage")
    public BaseResponse<PageVo> queryChartPage(@RequestBody QueryChartDto dto) {
        return chartService.queryChartPage(dto);
    }

    /**
     * 新增数据
     *
     * @param dto 添加对象
     * @return 新增结果
     */
    @PostMapping("/addChart")
    public BaseResponse<Object> addChart(@RequestBody AddChartDto dto) {
        chartService.addChart(dto);
        return ResultUtil.success(null);
    }

    /**
     * 修改数据
     *
     * @param dto
     * @return 修改结果
     */
    @PutMapping("/editChart")
    public BaseResponse<Object> editChart(@RequestBody EditChartDto dto) {
        chartService.editChart(dto);
        return ResultUtil.success(null);
    }

    /**
     * 删除图表
     *
     * @param id 图表id
     * @return 删除结果
     */
    @DeleteMapping("/deleteChart")
    public BaseResponse<Object> deleteChart(Long id) {
        chartService.deleteChart(id);
        return ResultUtil.success(null);
    }

    /**
     * 删除图表
     *
     * @param dto
     * @return 删除结果
     */
    @PostMapping("/genChartByAI")
    public BaseResponse<GenChartVo> genChartByAI(@RequestPart("file") MultipartFile file, @Valid GenChartByAIDto dto) {
        return chartService.genChartByAI(file, dto);
    }

}

